﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Configuration;
using System.Text;

namespace IntelligentCMS
{
    public partial class CMSWYSIWYG : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            loadHTML("one.html");
        }

        protected void loadHTML(String filename)
        {
            string loadPath = ConfigurationSettings.AppSettings["serverpath"] + ConfigurationSettings.AppSettings["DocumentsPath"];
            loadPath += filename;

            StreamReader sr = File.OpenText(loadPath);
            testarea.InnerText = sr.ReadToEnd();
            sr.Close();
        }

        protected void saveHTML(object sender, EventArgs e)
        {
            testlabel.Text = "done";

            string savePath = ConfigurationSettings.AppSettings["serverpath"] + ConfigurationSettings.AppSettings["DocumentsPath"];
            string filename = "one.html";
            savePath += filename;

            try
            {
                FileStream fs = new FileStream(savePath, FileMode.Create, FileAccess.ReadWrite);

                StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
                sw.Write("<html><body>");
                sw.Write(testarea.InnerText);
                sw.Write("</body></html>");
                sw.Close();

                /*BinaryWriter bw = new BinaryWriter(fs);
                bw.Write(testarea.InnerText);
                bw.Close();*/
            }
            catch (Exception ex)
            {

            }

        }
    }
}